#include "GameEntity.h"


GameEntity::GameEntity(): m_ptr_bitmap(NULL), m_ptr_scene(NULL)
{ }


GameEntity::GameEntity(QGraphicsScene * scene): m_ptr_bitmap(NULL), m_ptr_scene(scene)
{
    if (m_ptr_scene != NULL)
    {
        addToScene(m_ptr_scene);
    }
}


GameEntity::GameEntity(const GameEntity &obj, bool copyScene): m_ptr_bitmap(obj.m_ptr_bitmap)
{
    if (copyScene)
    {
        m_ptr_scene = obj.m_ptr_scene;
        if (m_ptr_scene != NULL)
        {
            addToScene(m_ptr_scene);
        }
    }
    else
    {
        m_ptr_scene = NULL;
    }
}


GameEntity::~GameEntity()
{
    removeFromScene();
}


GameEntity& GameEntity::operator = (const GameEntity & obj)
{
    m_ptr_bitmap = obj.m_ptr_bitmap;
    m_ptr_scene = obj.m_ptr_scene;
    if (m_ptr_scene != NULL)
    {
        addToScene(m_ptr_scene);
    }
    return *this;
}


void GameEntity::addToScene(QGraphicsScene * scene)
{
    removeFromScene();
    m_ptr_scene = scene;
    if (m_ptr_scene != NULL)
    {
        m_ptr_scene->addItem(this);
    }
}


void GameEntity::removeFromScene()
{
    if (m_ptr_scene != NULL)
    {
        m_ptr_scene->removeItem(this);
        m_ptr_scene = NULL;
    }
}
